import React, { Component } from 'react';
class App2 extends Component {
    constructor(props) {
        super(props);
        this.state = {
            arr:['青春再见','你好庚子','小酒馆','玉林路','成都']
        }
    }
    render() { 
        const {arr}=this.state;
        const list=arr.map((item,i)=><li key={i}>{item}</li>)
        return (
            <>
            <button onClick={this.add}>添加</button>
            <input type="text" ref="txt"/>
            <ul>{list}</ul>
            {/* <ul>{arr.map((item,i)=><li key={i}>{item}</li>)}</ul> */}
            </>
        );
    };
    add=()=>{
        const {arr}=this.state;
        // console.log(this.refs.txt.value)
        arr.push(this.refs.txt.value);
        this.setState({arr});
    }

}
 
export default App2;